﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

namespace FYPDemo
{
    public partial class WebForm12 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindStatus();
            }
        }

        protected void OrderSelection_GView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                string datefrom = "";
                string dateto = "";
                int index = Convert.ToInt32(e.CommandArgument);
                string orderID = OrderSelection_GView.DataKeys[index].Values["OrderID"].ToString();

                if (Session["dateFrom"] != null)
                { datefrom = Session["datefrom"].ToString() + " 00:00:00.000"; }

                if (Session["dateTo"] != null)
                { dateto = Session["dateto"].ToString() + " 23:59:59.998"; }

                DataTable dt = report.MemberTransactionReport(orderID, datefrom, dateto);

                if (dt.Rows.Count > 0)
                {
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
                else
                {
                    MemberText.Style.Add("display", "block");
                }
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string orderID = txtOrderID.Text;
            string DateFrom = "";
            string DateTo = "";
            string DatePaidFrom = "";
            string DatePaidTo = "";
            int status = Convert.ToInt32(ddlStatus.SelectedValue);
            //suppose use session to get the memberName
            string memberName = "cs";

            if (txtDateCreatedFrom.Text != "")
            {
                DateFrom = txtDateCreatedFrom.Text + " 00:00:00.000";
                Session["DateFrom"] = txtDateCreatedFrom.Text;
            }
            if (txtDateCreatedTo.Text != "")
            {
                DateTo = txtDateCreatedTo.Text + " 23:59:59.998";
                Session["DateTo"] = txtDateCreatedTo.Text;
            }
            if (txtDatePaidFrom.Text != "")
            {
                DatePaidFrom = txtDatePaidFrom.Text + " 00:00:00.000";
                Session["DatePaidFrom"] = txtDatePaidFrom.Text;
            }
            if (txtDatePaidTo.Text != "")
            {
                DatePaidTo = txtDatePaidTo.Text + " 23:59:59.998";
                Session["DatePaidTo"] = txtDatePaidTo.Text;
            }

            DataTable dt = report.TransactionReportForSelectingOrder(orderID, DateFrom, DateTo, DatePaidFrom, DatePaidTo,status, memberName);
            OrderSelection_GView.DataSource = dt;
            OrderSelection_GView.DataBind();
        }

        protected void bindStatus()
        {
            DataTable dt = new DataTable();

            dt = Common.bindStatus();

            ddlStatus.DataSource = dt;
            ddlStatus.DataTextField = "Status";
            ddlStatus.DataValueField = "ID";
            ddlStatus.DataBind();
        }
    }
}